package java复习202408.F_多线程验证;

import org.junit.jupiter.api.Test;

import java.util.concurrent.*;

public class f2_线程池验证 {
    // 自定义线程池
    @Test
    public void test(){
        ThreadPoolExecutor testThreadPool = new ThreadPoolExecutor(
                2,
                10,
                10l,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(),
//                Executors.defaultThreadFactory(),
                new ThreadFactory() {
                    @Override
                    public Thread newThread(Runnable r) {
                        return new Thread(r,"子线程");
                    }
                },
                new ThreadPoolExecutor.CallerRunsPolicy());

        testThreadPool.execute(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName());
            }
        });

        testThreadPool.execute(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName());
            }
        });


    }
}
